package com.lihepeng.leecode.solid_aim_offer.tree;

/**
 *
 */
public class Solution82 {
    /**
     *
     * @param root TreeNode类
     * @param sum int整型
     * @return bool布尔型
     */
    public boolean hasPathSum (TreeNode root, int sum) {
        if (root == null) {
            return false;
        }
        return dfs(root,sum);
    }
    private boolean dfs(TreeNode root, int sum){
        if (root == null) {
            return false;
        }
        int target = sum - root.val;
        if (root.left ==null && root.right ==null && target ==0) {
            return true;
        }

        return dfs(root.left,sum) && dfs(root.right,sum);
    }
}
